//
//  ExampleViewController.swift
//  Skeleton
//
//  Created by hubin on 2025/6/26.
//

import UIKit

class ExampleViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSize(width: 300, height: 30)
        layout.sectionInset = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
        let collectionview = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
        collectionview.register(CollectionViewCell.self, forCellWithReuseIdentifier: NSStringFromClass(CollectionViewCell.self))
        collectionview.register(CollectionViewCell2.self, forCellWithReuseIdentifier: NSStringFromClass(CollectionViewCell2.self))
        collectionview.delegate = self
        collectionview.dataSource = self
        collectionview.backgroundColor = .red
        view.addSubview(collectionview)
        
//        collectionview.reloadData()
        
        collectionview.showSkeletonWithDataSource()

        DispatchQueue.main.asyncAfter(deadline: .now() + 5.0) {
            collectionview.hideTabSkeleton()
        }
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension ExampleViewController:UICollectionViewDelegate {
    
}

extension ExampleViewController:UICollectionViewDataSource {
    public func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 2
    }
    
    public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if indexPath.section == 0 {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(CollectionViewCell.self), for: indexPath)
            return cell
        }else{
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(CollectionViewCell2.self), for: indexPath)
            return cell
        }
    }
    
}
